package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponDiscountDTO;
import com.tianji.promotion.domain.dto.OrderCouponDTO;
import com.tianji.promotion.domain.dto.OrderCourseDTO;
import com.tianji.promotion.domain.query.UserCouponQuery;
import com.tianji.promotion.domain.vo.UserCouponPageVO;
import com.tianji.promotion.service.IUserCouponService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户领取优惠券的记录，是真正使用的优惠券信息 前端控制器
 * </p>
 *
 * @author hrz
 * @since 2025-09-02
 */
@RestController
@RequestMapping("/user-coupons")
@RequiredArgsConstructor
public class UserCouponController {

    private final IUserCouponService userCouponService;

    @PostMapping("/{id}/receive")
    @ApiOperation("领取优惠券")
    public void getUserCoupon(@PathVariable Long id) {
        userCouponService.receiveCoupon(id);
    }

    @ApiOperation("兑换码兑换优惠券接口")
    @PostMapping("/{code}/exchange")
    public void exchangeCoupon(@PathVariable("code") String code){
        userCouponService.exchangeCoupon(code);
    }

    @GetMapping("/page")
    @ApiOperation("查询我的优惠券")
    public PageDTO<UserCouponPageVO> queryPage(@RequestBody UserCouponQuery query){
        return userCouponService.queryPage(query);
    }

    @PostMapping("/available")
    @ApiOperation("查询可用优惠券")
    public List<CouponDiscountDTO> queryAvailableCoupons(
            @RequestBody List<OrderCourseDTO> courses){
        return userCouponService.queryAvailableCoupons(courses);
    }

    @PostMapping("/discount")
    @ApiOperation("查询优惠券的优惠明细")
    public CouponDiscountDTO queryCouponDiscount(@RequestBody OrderCouponDTO orderCouponDTO){
        return userCouponService.queryCouponDiscount(orderCouponDTO);
    }

    @PutMapping("/use")
    @ApiOperation("使用优惠券")
    public void useCoupon(@RequestParam("couponIds") List<Long> UserCouponIds){
        userCouponService.useCoupon(UserCouponIds);
    }

    @PutMapping("/refund")
    @ApiOperation("优惠券退款")
    public void refundCoupon(@RequestParam("couponIds") List<Long> UserCouponIds){
        userCouponService.refundCoupon(UserCouponIds);
    }

    @GetMapping("/rules")
    public List<String> queryDiscountRules(
            @RequestParam("couponIds") List<Long> userCouponIds){
        return userCouponService.queryDiscountRules(userCouponIds);
    }
}
